<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>省份信息查询</title>
<script type="text/javascript" src="../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../js/jquery.pagination.js"></script>
<script type="text/javascript" src="../../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/public.js"></script>
<script type="text/javascript" src="../../js/alert.js"></script>
<script type="text/javascript" src="../../js/loadSchoolGrade.js"></script>
<script type="text/javascript" src="../../js/jquery-ui/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="../../js/jquery-ui/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="../../css/bootstrap.css">
</head>
<body>
	<div>
		<form id="form1">
			<table class="table table-bordered .table-condensed">
				<tr>
					<td>编号:</td>
					<td id="id"></td>
				</tr>
				<tr>
					<td>国家:</td>
					<td>
						<select name="updateProvince.nations" id="nations" style="width: 90px;">
						</select>
					</td>
				</tr>
				<tr>
					<td>省份名:</td>
					<td>						 
						<input type="text" name="name" />
						<input type="hidden" name="id" />
					</td>
				</tr>
				<tr>
					<td colspan="4" style="text-align: center;">
						<button type="button" onclick="updateProvince();" class="btn btn-info">修改</button>
					</td>
				</tr>
			</table>
		</form>
	</div>
     
    <script type="text/javascript">
		var href = location.href.split("=");
		var regionId = href[1];
		getProvince(regionId);
		

    	//查看省份信息
    	function getProvince(id){
    		$.ajax({
    			url : "../../province/get.ao",
    			type : 'POST',
    			data :{
    				"id" : id
    			},
    			cache : false,
    			beforeSend : ajaxstar,
    			complete : ajaxend,
    			dataType : "json",
    			success : function(data) {
    				if (data["state"] == "success") {
    					$("table").find("td").each(function(){//不更改的字段
    						var id = $(this).attr("id");
    						if(id != null && typeof(id) != "undefined"){
    							$(this).html(data["result"][id]);
    						}
    					});
    					$("table").find("input").each(function(){//文本框内容
    						var name = $(this).attr("name");
    						if(name != null && typeof(name) != "undefined"){
    							$(this).val(data["result"][name]);
    						}
    					});
    					$("table").find("select").each(function(){//下拉列表框
    						var name = $(this).attr("name");
    						if(name == "updateProvince.nations"){
								var nations = data["result"]["nations"];
								var nationsHtml = "";
								var isuse = "";
								for(var i = 0; i < nations.length; i++){
									if(nations[i]["isuse"] == 1){
										isuse = nations[i]["id"];
									}
									nationsHtml += "<option value='"+nations[i]["id"]+"'>"+nations[i]["name"]+"</option>";
								}
								
								$(this).html(nationsHtml);//填空下拉列表框选项
								$(this).val(isuse);//设置选中项
							}else{
								$(this).val(data["result"][name]);
							}
    					});
    				} else {
    					sAlert(data["result"]);
    				}
    			}
    		});
    	}
    	
    	//修改省份
    	function updateProvince(){
       		$.ajax({
       			url : "../../province/update.ao",
       			type : 'POST',
       			data :$("#form1").serialize(),
       			cache : false,
       			beforeSend : ajaxstar,
       			complete : ajaxend,
       			dataType : "json",
       			success : function(data) {
   					sAlert(data["result"]);
       				if(data["state"] == "success"){
       					location.reload();
       				}
       			}
       		});
    	}
    </script>
</body>
</html>